<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>
        // function ready(){
        //     var btn=document.getElementById("btn1");
        //     btn.onclick=function (){
        //     alert("按钮单击了");
        // }
        //}
        window.onload = function () {

          
                var btn = document.getElementById("btn1");
                btn.onclick = function () {
                    alert("按钮单击了");
                }
            }
    </script>
</head>

<body>
    <button id="btn1" onclick="">按钮</button>

</body>

</html>